Rather than doing some of your work in Stata and some of your work in ArcGIS, you can do a lot of it in Python. The geopandas package is the geospatial version of the pandas package, and allows you do perform spatial operations, including drawing buffers, calculating distances, calculating areas, spatial joins, etc.
We'll do a quick example of merging our tabular data with geospatial. Often, we have a table of values we'd like to map. We need polygons attached to our geography, and then we want to quickly visualize. Our quick example will do a little bit of cleaning using pandas, merge on the polygon geometry, then plot the map (static and interactive map) using geopandas (static map) and folium (interactive map).
Resources:
Quickly, we'll grab the CA county boundaries from CA Open Data Portal.
https://gis.data.ca.gov/datasets/CALFIRE-Forestry::california-county-boundaries/data
Navigate to API > GeoJSON, and copy the URL.
| OBJECTID | COUNTY_NAME | COUNTY_ABBREV | COUNTY_NUM | COUNTY_CODE | COUNTY_FIPS | ISLAND | GlobalID | SHAPE_Length | SHAPE_Area | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | Alameda | ALA | 1 | 01 | 001 | None | {E6F92268-D2DD-4CFB-8B79-5B4B2F07C559} | 2.538264 | 0.217411 | MULTIPOLYGON (((-122.27125 37.90503, -122.2702... |
| 1 | 2 | Alpine | ALP | 2 | 02 | 003 | None | {870479B2-480A-494B-8352-AD60578839C1} | 2.170420 | 0.198471 | MULTIPOLYGON (((-119.58667 38.71420, -119.5865... |
<Geographic 2D CRS: EPSG:4326> Name: WGS 84 Axis Info [ellipsoidal]: - Lat[north]: Geodetic latitude (degree) - Lon[east]: Geodetic longitude (degree) Area of Use: - name: World - bounds: (-180.0, -90.0, 180.0, 90.0) Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
| geometry | |
|---|---|
| 0 | MULTIPOLYGON (((-122.27125 37.90503, -122.2702... |
| 1 | MULTIPOLYGON (((-119.58667 38.71420, -119.5865... |
| 2 | MULTIPOLYGON (((-120.07246 38.70276, -120.0724... |
| 3 | MULTIPOLYGON (((-121.07661 39.59729, -121.0794... |
| 4 | MULTIPOLYGON (((-120.01792 38.43586, -120.0178... |
| geometry | |
|---|---|
| 0 | MULTIPOLYGON (((5327843.636 3270649.517, 53281... |
| 1 | MULTIPOLYGON (((6107872.113 3543254.346, 61079... |
| 2 | MULTIPOLYGON (((5968863.196 3541606.326, 59687... |
| 3 | MULTIPOLYGON (((5691714.322 3875581.366, 56907... |
| 4 | MULTIPOLYGON (((5982508.552 3443893.703, 59825... |
Santa Barbara 6 Ventura 5 Los Angeles 3 Solano 1 Riverside 1 Mariposa 1 Butte 1 Siskiyou 1 Imperial 1 Inyo 1 Kings 1 Santa Clara 1 Orange 1 San Joaquin 1 Sierra 1 Contra Costa 1 Napa 1 Modoc 1 Colusa 1 San Mateo 1 Amador 1 San Benito 1 Merced 1 Fresno 1 Sonoma 1 Nevada 1 Trinity 1 Yolo 1 San Luis Obispo 1 El Dorado 1 Sutter 1 Monterey 1 Placer 1 Alameda 1 San Bernardino 1 Yuba 1 Tulare 1 Calaveras 1 Lassen 1 Humboldt 1 Alpine 1 Stanislaus 1 San Diego 1 Tehama 1 Tuolumne 1 Plumas 1 Santa Cruz 1 Lake 1 Madera 1 Glenn 1 San Francisco 1 Mendocino 1 Sacramento 1 Mono 1 Marin 1 Del Norte 1 Kern 1 Shasta 1 Name: COUNTY_NAME, dtype: int64
<AxesSubplot:>
| COUNTY_NAME | geometry | OBJECTID | COUNTY_ABBREV | COUNTY_NUM | COUNTY_CODE | COUNTY_FIPS | ISLAND | GlobalID | SHAPE_Length | SHAPE_Area | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Alameda | POLYGON ((5327843.636 3270649.517, 5328125.534... | 1 | ALA | 1 | 01 | 001 | None | {E6F92268-D2DD-4CFB-8B79-5B4B2F07C559} | 2.538264 | 0.217411 |
| 1 | Alpine | POLYGON ((6107872.113 3543254.346, 6107910.593... | 2 | ALP | 2 | 02 | 003 | None | {870479B2-480A-494B-8352-AD60578839C1} | 2.170420 | 0.198471 |
| 2 | Amador | POLYGON ((5968863.196 3541606.326, 5968719.695... | 3 | AMA | 3 | 03 | 005 | None | {4F45B3A6-BE10-461C-8945-6B2AAA7119F6} | 2.924268 | 0.161961 |
| 3 | Butte | POLYGON ((5691714.322 3875581.366, 5690777.192... | 4 | BUT | 4 | 04 | 007 | None | {44FBA680-AECC-4E04-A499-29D69AFFBD4A} | 4.210365 | 0.455899 |
| 4 | Calaveras | POLYGON ((5982508.552 3443893.703, 5982516.557... | 5 | CAL | 5 | 05 | 009 | None | {D11EF739-4A1E-414E-BFD1-E7DCD56CD61E} | 2.989673 | 0.275908 |
| COUNTY_NAME | COUNTY_FIPS | geometry | fips | |
|---|---|---|---|---|
| 0 | Alameda | 001 | POLYGON ((5327843.636 3270649.517, 5328125.534... | 06001 |
| 1 | Alpine | 003 | POLYGON ((6107872.113 3543254.346, 6107910.593... | 06003 |
| county | state | fips | date | Lat | Lon | cases | deaths | incident_rate | people_tested | state_cases | state_deaths | new_cases | new_deaths | new_state_cases | new_state_deaths | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 62 | Autauga | Alabama | 01001 | 2020-03-24 07:00:00+00:00 | 32.539527 | -86.644082 | 1 | 0 | 1.789901 | <NA> | 298 | 0 | 1 | 0 | 74 | 0 |
| 63 | Autauga | Alabama | 01001 | 2020-03-25 07:00:00+00:00 | 32.539527 | -86.644082 | 5 | 0 | 8.949507 | <NA> | 472 | 1 | 4 | 0 | 174 | 1 |
geopandas.geodataframe.GeoDataFrame
| COUNTY_NAME | COUNTY_FIPS | geometry | fips | county | state | date | Lat | Lon | cases | deaths | incident_rate | people_tested | state_cases | state_deaths | new_cases | new_deaths | new_state_cases | new_state_deaths | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Alameda | 001 | POLYGON ((5327843.636 3270649.517, 5328125.534... | 06001 | Alameda | California | 2020-03-03 08:00:00+00:00 | 37.646294 | -121.892927 | 1 | 0 | 0.059833 | <NA> | 25 | 0 | 1 | 0 | 4 | 0 |
| 1 | Alameda | 001 | POLYGON ((5327843.636 3270649.517, 5328125.534... | 06001 | Alameda | California | 2020-03-04 08:00:00+00:00 | 37.646294 | -121.892927 | 1 | 0 | 0.059833 | <NA> | 35 | 1 | 0 | 0 | 10 | 1 |
pandas.core.frame.DataFrame
| county | state | fips | date | Lat | Lon | cases | deaths | incident_rate | people_tested | state_cases | state_deaths | new_cases | new_deaths | new_state_cases | new_state_deaths | COUNTY_NAME | COUNTY_FIPS | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Alameda | California | 06001 | 2020-03-03 08:00:00+00:00 | 37.646294 | -121.892927 | 1 | 0 | 0.059833 | <NA> | 25 | 0 | 1 | 0 | 4 | 0 | Alameda | 001 | POLYGON ((5327843.636 3270649.517, 5328125.534... |
| 1 | Alameda | California | 06001 | 2020-03-04 08:00:00+00:00 | 37.646294 | -121.892927 | 1 | 0 | 0.059833 | <NA> | 35 | 1 | 0 | 0 | 10 | 1 | Alameda | 001 | POLYGON ((5327843.636 3270649.517, 5328125.534... |
geopandas.geodataframe.GeoDataFrame
| COUNTY_NAME | COUNTY_FIPS | geometry | fips | county | state | date | Lat | Lon | cases | deaths | incident_rate | people_tested | state_cases | state_deaths | new_cases | new_deaths | new_state_cases | new_state_deaths | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Alameda | 001 | POLYGON ((5327843.636 3270649.517, 5328125.534... | 06001 | Alameda | California | 2021-01-20 08:00:00+00:00 | 37.646294 | -121.892927 | 1 | 0 | 4065.746481 | <NA> | 3055568 | 34445 | 0 | 0 | 0 | 4 |
| 1 | Alpine | 003 | POLYGON ((6107872.113 3543254.346, 6107910.593... | 06003 | Alpine | California | 2021-01-20 08:00:00+00:00 | 38.596786 | -119.822359 | 1 | 0 | 6465.899026 | <NA> | 3055568 | 34445 | 0 | 0 | 0 | 4 |
<AxesSubplot:>
<AxesSubplot:>